/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import bean.Candidato;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import negocio.NegocioCandidato;

/**
 *
 * @author jcrbsa
 */
public class StartSessionCadastro extends HttpServlet {

  
        
   
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
         HttpServletRequest req = (HttpServletRequest) request;
        NegocioCandidato fachada = NegocioCandidato.getInstance();
        HttpSession session = req.getSession(true);
        Candidato candidato = new Candidato();
        String cpf = req.getParameter("cpf");
        String nome = req.getParameter("nome");
        String email = req.getParameter("email");
        String senha = req.getParameter("senha");
        candidato.setCpf(cpf);
        boolean valor =  fachada.procuraCPF(candidato);
        System.out.println(valor);
    
        if (cpf != null) {


            if ( valor  == true) {
                    
                 
                        
                    System.out.println("Já existe Candidato  - continua na mesma pagina");
                    req.getRequestDispatcher("/index.jsp").forward(request, response);

                }
            } 
            if (valor == false){
                  System.out.println("Não existe candidato - 'index'");
                  session.setAttribute("status", "logado ");
                  session.setAttribute("cpf", cpf);
                  session.setAttribute("nome", nome);
                  session.setAttribute("email", email);
                  session.setAttribute("senha",senha);
                  
                  req.getRequestDispatcher("/continuacaocadastro.jsp").forward(request, response);

                
            }
                

        }
   
    

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
